﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InnovTech.Wpf.Unittest.Test.TestStuffs;
using InnovTech.Wpf.Command;
using AutomationLib;
using System.Windows.Input;
using System.Windows;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading;
using InnovTech.Wpf.Automation;

namespace InnovTech.Wpf.Unittest.Test
{
    [TestClass]
    public class TestAutoTestHelper
    {


        [TestMethod]
        public void TestRunUITest()
        {
            //Uses local variables and PropertyChangedEvent or Command to assert
            int count = 0;
            object cbSelection = null;


            AutoTestHelper helper = new AutoTestHelper();
            helper.RunUITest(() =>
            {
                BtnTestControl control = new BtnTestControl();
                VmBtnTestControl viewModel = new VmBtnTestControl();
                viewModel.TestButtonCommand = new DelegateCommand(() => count++);
                viewModel.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName.Equals("ComboBoxSelection"))
                    {
                        cbSelection = viewModel.ComboBoxSelection;
                    }
                };
                control.DataContext = viewModel;
                return control;
            }, () =>
            {
                StringBuilder sb = new StringBuilder("A test string created by Automation");
                sb.AppendLine();
                sb.AppendLine("lalala");


                helper.ProcessTextInput("tbTest", sb.ToString());
                helper.ProcessButtonClick("CommandButton");
                helper.ProcessComboBoxSelection("cbTest", "ccc");
                Thread.Sleep(2000);
                helper.ProcessSelection("cbTest", "bbb");
                Thread.Sleep(2000);
                

                helper.ProcessSelection("lbTest", "ccc");
                Thread.Sleep(2000);

                helper.ProcessSelection("tcTest", "tabItem2");
                Thread.Sleep(2000);

                helper.ProcessToggle("cboxTest");
                Thread.Sleep(2000);
                helper.ProcessToggle("cboxTest");
                Thread.Sleep(2000);

                helper.ProcessToggle("tbtnTest");
                Thread.Sleep(2000);
                helper.ProcessToggle("tbtnTest");
                Thread.Sleep(2000);

                helper.ProcessRadioButtonSelection("rbTest1");
                Thread.Sleep(2000);
                helper.ProcessRadioButtonSelection("rbTest2");
                Thread.Sleep(2000);
                
            });
            Assert.AreEqual(1, count);
            Assert.AreEqual("bbb", cbSelection);
            
        }

        //int count = 0;

        //[TestMethod]
        //public void TestMethod1()
        //{
        //    AutoTestHelper helper = new AutoTestHelper();
        //    helper.RunTest(() =>
        //    {

        //        BtnTestControl control = new BtnTestControl();
        //        VmBtnTestControl viewModel = new VmBtnTestControl();
        //        viewModel.TestButtonCommand = new DelegateCommand(TestButtonCommandExecute);
        //        control.DataContext = viewModel;

        //        helper.CreateTestLogic(control, () =>
        //        {
        //            helper.TestButtonClick(control, "CommandButton");
                    
        //        })();
                
        //    });
        //    Assert.AreEqual(1, count);
        //}


        
        //private void TestButtonCommandExecute(object parame)
        //    //ExecutedRoutedEventArgs args)
        //{
        //    count++;
        //}
    }


}
